﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XYTXL.API;
using XYTXL.AppCode;
using XYTXL.Data;

namespace XYTXL.Web.View.UCMangForm
{
    public partial class XWGL : FormUControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                new CommonHelp.BindData().BindLM(ddlLM1);
                new CommonHelp.BindData().BindLM(ddlLM2, ddlLM1.SelectedValue);
            }
        }

        /// <summary>
        /// 重写父类的保存数据方法
        /// </summary>
        /// <param name="intFormID">数据ID</param>
        /// <param name="strActionType">操作类型("ADD":"添加","UPDATE":"修改")</param>
        /// <returns></returns>
        public override bool SaveForm(int intFormID, string strActionType, int pid)
        {
            //执行 父类的方法
            base.SaveForm(intFormID, strActionType);

            //保存数据
            JH_MH_XWGL Model = new JH_MH_XWGLB().GetEntity(d => d.ID == intFormID);
            Model.Title = txtTitle.Text;
            Model.Source = txtSource.Text;
            Model.IsShow = Convert.ToInt32(ddlIsShow.SelectedValue);
            Model.Files = txtTP.Text;
            Model.Type = Convert.ToInt32(ddlLM2.SelectedValue);
            Model.Details = txtDetails.Text;
            return new JH_MH_XWGLB().Update(Model);
        }




        public override void initMangerForm(int intFormID, string strActionType)
        {
            base.initMangerForm(intFormID, strActionType);
            JH_MH_XWGL Model = new JH_MH_XWGLB().GetEntity(d => d.ID == intFormID);
            txtTitle.Text = Model.Title;
            txtSource.Text = Model.Source;
            txtTP.Text = Model.Files;
            txtDetails.Text = Model.Details;
            ddlIsShow.SelectedValue = Model.IsShow.ToString();

            JH_MH_LMGL lm = new JH_MH_LMGLB().GetEntity(d => d.ID == Model.Type);
            new CommonHelp.BindData().BindLM(ddlLM1);
            ddlLM1.SelectedValue = lm.TopID.ToString();
            new CommonHelp.BindData().BindLM(ddlLM2, ddlLM1.SelectedValue);
            ddlLM2.SelectedValue = Model.Type.ToString();
        }

        protected void ddlLM1_SelectedIndexChanged(object sender, EventArgs e)
        {
            new CommonHelp.BindData().BindLM(ddlLM2, ddlLM1.SelectedValue);
        }
    }
}